import { Component } from 'react';

import { Toast, Button , Group, TextField,} from 'saltui';

import DB from '../../../app/db';

import './PageHome.less';


export default class PageHome extends Component {


 constructor(props) {
    super(props);
    let id = this.props.params.id;
    let noticeId = this.props.params.noticeId
    this.state = {
      id: id,
      noticeId:noticeId,
      reason:''
    };

    var thirdMenuType = getLoginUserInfo().thirdMenuType;
    if(thirdMenuType == 'DING'){
      dd.biz.navigation.setTitle({
          title : "驳回",//控制标题文本，空字符串表示显示默认文本
          onSuccess : function(result) {},
          onFail : function(err) {}
      });
    }else if(thirdMenuType =='MH'){
      !!emp&&emp.window.setTitle({
          title: {
              text: "驳回",
              icon: '',
              actionmenu: {}
          },
      });
    }
  }

  componentDidUpdate (){

    
  }

  
handleTextChange(name, newValue) {
    this.setState({
      [name]: newValue,
    });
  }
  
  submit(){
    if (this.state.reason.trim()=='') {
      Toast.show({
              type: 'error',
              content: '请填写驳回原因',
              onHide: function () {
              }
          });
      return;
    }

    let t = this;
    let param = {
      id:this.state.id,
      noticeInfoId:this.state.noticeId,
      status:'2',
      reason:this.state.reason

    };

    DB.SomeModuleAPI.editApplyRecordInfo(param)
        .then((content) => {

          console.log("content: " + JSON.stringify(content));
          Toast.show({
          type: 'success',
              content: '提交成功'
           });

          //返回至列表页面
          history.go(-2);
          
        }).catch((error) => {
          
            if(typeof(error.errorMsg) == 'undefined'){
              Toast.show({
              type: 'error',
              content: '提交出错'
               });
            }else{
              Toast.show({
              type: 'error',
              content: error.errorMsg
               });
            }
        }); 

  }

  cancel(){
    history.back();
  }

  render() {
    let t = this;
    return (
      <div>
          <div>
            <Group.List >
              <TextField
                required
                label="驳回原因" minRows={6} maxRows={10}
                placeholder="请输入驳回原因"
                value={t.state.reason}
                onChange={(value) => { t.handleTextChange('reason', value); }}
              />
            </Group.List>
          </div>

          <div >
              <Button.Group >
                  <Button type="primary" display="inline" onClick={this.submit.bind(this)}>提交</Button>
                  <Button type="secondary" display="inline" onClick={this.cancel.bind(this)}>取消</Button>             
              </Button.Group>
          </div>
        
    </div>);
  }
}


